
class FirstPage extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            list: [
                { ismode: 1 },
            ],
            thumburl: '',
            name: '',
            fangjianhtml: [],
            input_name: '',
            sdarr: [],
            showpage: !1,
            showbtn: !0,
            sel_fang: -1,
            showpage1: !1,
            select1id: -1,
            priceitem: { price: 0, },
            select_pricechoseid: 0,
            select_priceid: 0,
            mbkjlist: [
            ],//模板空间
            id: '0',
            antdhtml: [],
            partcount: 1,
            parts: [{ src: '' }, { src: '' }, { src: '' }],
            categorylist: [],
            select_swiperlink: { name: '请选择' },
            swiperimglist: [],
            input_mbname: '模板房间',
            category_select_list: [],
            recommendtablehtml: [],
            recommendlist: [],
            detail: { id: -1, name: '' },
            goods_select_html: [],
            currentswipertype: 0,
            swiperlinkhtml: [],
            swipertablehtml: [],
            swiperimghtml: [],
            subtitle: '',
            totalamount: 0,
            showmoban: !1,
            showeditprice: !1,
            moban: {
                cp: [
                    { width: 0, height: 0, deep: 0, singleprice: 0 }
                ],
                wj: [
                    { count: 0, singleprice: 0 }

                ],
                name: '',
                amount: 0
            },
            exportlist: [

            ],
            // exportlist1:[
            //     {
            //         room:{
            //             name:'',
            //             id:''
            //         },
            //         wjtotal:0,
            //         cptotal:0,
            //         cptotalcount:0,
            //         amount:0,
            //         wj:[{
            //             pid: '',
            //             cid: '-1',
            //             cid1: '-1',
            //             cname: '',
            //             height: "",
            //             width: "",
            //             deep: "",
            //             singleprice: 0,
            //             count: '',
            //             amount: '',
            //             unit: '',
            //             lmsm: '',
            //             mbcz: '',
            //             gtcz: '',
            //         }

            //         ],
            //         cp:[
            //             {
            //                 pid: '',
            //                 cid: '-1',
            //                 cid1: '-1',
            //                 cname: '',
            //                 height: "",
            //                 width: "",
            //                 deep: "",
            //                 singleprice: 0,
            //                 count: '',
            //                 amount: '',
            //                 unit: '',
            //                 lmsm: '',
            //                 mbcz: '',
            //                 gtcz: '',

            //             }
            //         ]
            //     }
            // ],
            swiper: {
                imgs: [],
                links: []
            },
            fileimgshow: !0,
            imgstate: '',
            imgsrc: '',
            to: '',
        };
    }

    formatlist(list, categorylist) {
        console.log(list, 'list-formatlist');
        let pricearr = { 'GT': [], 'WJ': [] };
        list.forEach((x, i) => {
            if (!x.items['cp']) {

                // console.log("x.items['cp']");
                let items = {}
                items['cp'] = x.items.filter(x => { return x.type == 'CP' })
                items['wj'] = x.items.filter(x => { return x.type == 'WJ' })
                list[i]['items'] = items
            } else {

                if (x.items.cp) { 
                    x.items.cp.forEach(y => {
                        
                        if (y.cid1 > 0) {
                            let i = categorylist.findIndex(x => x.id == y.cid1)
                            if (i > -1) {
                                categorylist[i]['name'] = y.cname1
                            }
                            pricearr['GT'].push({ id: y.cid1, name: y.cname1, price: y.singleprice })
                        }
                    })
                }
                if (x.items.wj) {
                    x.items.wj.forEach(y => {
                        if (y.cid1 > 0) {
                            let i = categorylist.findIndex(x => x.id == y.cid1)
                            if (i > -1) {
                                categorylist[i]['name'] = y.cname1
                            }
                            pricearr['WJ'].push({ id: y.cid1, name: y.cname1, price: y.singleprice })
                        }
                    })
                }


            }
            pricearr['WJ'] = arrDistinctByProp(pricearr['WJ'], 'id')
            pricearr['GT'] = arrDistinctByProp(pricearr['GT'], 'id')


        })
        console.log(pricearr, 'format--list');
        


        this.setState({ exportlist: list, pricearr, categorylist })

    }


    getxs(deep) {

        let ii = -1, { sdarr } = this.state;
        this.state.sdarr.forEach((x, i) => {
            if (deep > x.min && deep <= x.max) ii = i
        })
        let res = ii == -1 ? 1 : sdarr[ii].number
        // console.log({deep,res},'getxs');

        return res;
    }

    firstgetdata(id) {
        let totalamount = 0, fangjianhtml = []
        dzroom_getlist(res => {
            if (res.issuccess == 1) {
                fangjianhtml.push(<option value={-1}>请选择 </option>)
                res.list.forEach((x, i) => {
                    fangjianhtml.push(
                        <option key={i} value={x.id}>{x.name} </option>)
                })
                this.setState({ roomlist: res.list, fangjianhtml })
            }
        })


        dz_categetlist(cateres => {
            if (cateres.issuccess == 1) {
                let categorylist = cateres.list
                this.setState({ categorylist })
                dz_getcategorylist('XSSD', res_xssd => {
                    if (res_xssd.issuccess == 1) {
                        this.setState({ sdarr: res_xssd.list }, () => {
                            //  this.formatlist(list)
                            if (id != 'null') {
                                this.setState({ id }, () => {
                                    dz_projectdetail_getd(id, res => {
                                        let detail = res.data
                                        // console.log(uniq(res.data.roomids.split(',')),'uniq');
                                        if (detail.rawData == '') {
                                            dzroom_getlistbyid(
                                                uniq(res.data.roomids.split(',')).toString(), res => {
                                                    let { list } = res
                                                    if (list.length > 0) {
                                                        this.formatlist(list, categorylist)
                                                        this.setState({ input_name: res.name })
                                                        // dz_getcategorylist('XSSD', res => {
                                                        //     if (res.issuccess == 1) {
                                                        //         this.setState({ sdarr: res.list, input_name: res.name }, () => {
                                                        //             this.formatlist(list)
                                                        //         })
                                                        //     }
                                                        // })
                                                    }
                                                }
                                            )
                                        } else {
                                            // console.log(),'0000');
                                            let exportlist = JSON.parse(decodeurl(res.data.rawData))
                                            //  console.log(exportlist, 'listlist123');
                                            this.formatlist(exportlist, categorylist)

                                            this.setState({ input_name: detail.name })

                                        }
                                    })
                                })
                            }
                        })
                    }
                })
            }
        })




        // dz_categetlist(res => {
        //     if (res.issuccess == 1) {
        //         let { list } = res

        //         let cate_CPLBhtml = [], cate_GTCZhtml = [], cate_WJLBhtml = [], cate_WJCZhtml = [],cate_MBXHhtml=[],cate_LSFShtml=[],cate_GTXHhtml=[];
        //         let list_CPLB = list.filter(x => x.type == 'CPLB')
        //         let list_GTCZ = list.filter(x => x.type == 'GTCZ')
        //         let list_WJLB = list.filter(x => x.type == 'WJLB')
        //         let list_WJCZ = list.filter(x => x.type == 'WJCZ')
        //         let list_MBXH = list.filter(x => x.type == 'MBXH')
        //         let list_LSFS = list.filter(x => x.type == 'LSFS')
        //         let list_GTXH = list.filter(x => x.type == 'GTXH')
        //         let list_XSSD = list.filter(x => x.type == 'XSSD')
        //      //  console.log({ list_CPLB, list_GTCZ, list_WJLB, list_WJCZ }, 'list_GTCZ');
        //        console.log({list_GTCZ, }, 'list_GTCZ');


        //       cate_LSFShtml.push(<option value={-1}>请选择 </option>)
        //       list_LSFS.forEach((x, i) => {
        //         cate_LSFShtml.push(
        //               <option key={i} value={x.id}>
        //                 {x.name} 
        //                 </option>
        //           )
        //       })

        //       cate_GTXHhtml.push(<option value={-1}>请选择 </option>)
        //       list_GTXH.reverse().forEach((x, i) => {
        //         cate_GTXHhtml.push(
        //               <option key={i} value={x.id}>{x.name} 
        //               </option>

        //           )
        //       })

        //       cate_MBXHhtml.push(<option value={-1}>请选择 </option>)
        //       list_MBXH.reverse().forEach((x, i) => {
        //         cate_MBXHhtml.push(
        //               <option key={i} value={x.id}>{x.name} 
        //               </option>
        //           )
        //       })

        //         cate_CPLBhtml.push(<option value={-1}>请选择 </option>)
        //         list_CPLB.reverse().forEach((x, i) => {
        //             cate_CPLBhtml.push(
        //                 <option key={i} value={x.id}>{x.name} </option>
        //             )
        //         })

        //         cate_GTCZhtml.push(<option value={-1}>请选择 </option>)
        //         list_GTCZ.reverse().forEach((x, i) => {
        //             cate_GTCZhtml.push(
        //                 <option key={i} value={x.id}>{x.name} </option>
        //             )
        //         })

        //         cate_WJLBhtml.push(<option value={-1}>请选择 </option>)
        //         list_WJLB.reverse().forEach((x, i) => {
        //             cate_WJLBhtml.push(
        //                 <option key={i} value={x.id}>{x.name} </option>
        //             )
        //         })

        //         cate_WJCZhtml.push(<option value={-1}>请选择 </option>)
        //         list_WJCZ.reverse().forEach((x, i) => {
        //             cate_WJCZhtml.push(
        //                 <option key={i} value={x.id}>{x.name} </option>
        //             )
        //         })

        //         // catehtml1.push(<option value={-1}>请选择</option>)
        //         // res.list1.forEach((x, i) => {
        //         //     catehtml1.push(
        //         //         <option key={i} value={x.id}>{x.name} </option>
        //         //     )

        //         // })
        //         if (id != 'null') {
        //             this.setState({ id,sdarr:list_XSSD }, () => {
        //                 dz_projectdetail_getd(id, res => {
        //                     let detail = res.data
        //                     // console.log(uniq(res.data.roomids.split(',')),'uniq');
        //                     if (detail.rawData == '') {
        //                         dzroom_getlistbyid(
        //                             uniq(res.data.roomids.split(',')).toString(), res => {
        //                                 let { list } = res
        //                                 if (list.length > 0) {
        //                                     this.setState({ input_name: res.name })
        //                                     this.formatlist(list)
        //                                     // dz_getcategorylist('XSSD', res => {
        //                                     //     if (res.issuccess == 1) {
        //                                     //         this.setState({ sdarr: res.list, input_name: res.name }, () => {
        //                                     //             this.formatlist(list)
        //                                     //         })
        //                                     //     }
        //                                     // })
        //                                 }
        //                             }
        //                         )
        //                     } else {
        //                         // console.log(),'0000');
        //                         let exportlist = JSON.parse(decodeurl(res.data.rawData))
        //                         console.log(exportlist, 'listlist123');



        //                         this.formatlist(exportlist)

        //                         this.setState({ input_name: detail.name })

        //                     }
        //                 })
        //             })
        //         }




        //         this.setState({
        //             categorylist:list,
        //             cate_CPLBhtml, list_CPLB, cate_GTCZhtml, list_GTCZ, list_WJLB,list_LSFS,list_GTXH,list_MBXH
        //             , cate_WJLBhtml, cate_WJCZhtml, list_WJCZ,cate_MBXHhtml,cate_LSFShtml,cate_GTXHhtml
        //         })
        //     }

        // })

    }

    ccheck(id) {
        if (id != 'null') {
            let pwd = prompt('请输入密码')
            dz_category_checkpwd(md5(pwd + Constant.SALT), res => {
                if (res.data == true) {
                    this.firstgetdata(id)
                } else {
                    // this.ccheck(id)
                    alert('密码错误')
                    window.location.href = './dz_main.html'
                }
            })

        } else {
            this.firstgetdata(id)
        }
    }




    componentDidMount() {
        let id = GetQueryString('id'), totalamount = 0, fangjianhtml = []
        console.log(id, 'idid');
       
        haspwd(res => {
            if (res.data == true) {
                this.ccheck(id)
            } else {
                this.firstgetdata(id)
            }
        })


        // document.write("<script src='./antd/dist/antd.js'></script>")
        // let antdhtml = [];
        // antdhtml.push(
        //     <antd.Select showSearch value={item_cp.cid1} style={{ width: "100px" }} onChange={this.selectchange.bind(this, exportindex, 'WJ', i)} >
        //                                                                         <option value={-1}>请选择 </option>
        //                                                                         </antd.Select>
        // )
        // this.setState({antdhtml})





        // if (window.matchMedia) {
        //     var mediaQueryList = window.matchMedia('print');
        //     mediaQueryList.addListener(function(mql) {
        //         if (mql.matches) {
        //            // beforePrint();//
        //             console.log('beforePrint');
        //         } else {
        //             console.log('afterPrint');
        //            // afterPrint();
        //         }
        //     });
        //  }
        //     dz_getcategorylist('XSSD',res=>{
        //         if(res.issuccess==1){
        //             this.setState({sdarr:res.list})
        //     }
        //  })

        // if(id=='null'){
        //     this.addmoban()
        // }






        //  $('.modal1').hide()

        // this.freshlist()

    }
    freshlist() {
        dzroom_getlist(res => {
            if (res.issuccess == 1) {

                // this.formatlist(res.list); 
                let roomhtml = [];
                roomhtml.push(<option value={-1}>请选择 </option>)
                res.list.forEach(x => {
                    roomhtml.push(
                        <option value={x.id}>{x.name} </option>
                    )
                })

                this.setState({ list: res.list, roomhtml })

                console.log(res.list)
            }
        })




    }





    /**新建 */
    add() {
        // $('.modal1').show()
        var name = prompt('请输入房间名称')
        if (name != '') {
            aoedzroom({ name }, res => {
                if (res.issuccess == 1) {
                    this.freshlist()
                } else {
                    alert(res.msg)
                }
            })
        }
    }


    // 编辑
    edit(x) {
        var name = prompt('请编辑房间名称', x.name)
        if (name != '' && name != x.name) {
            //  console.log(name,'name');

            dz_projectdetail_add({ id: x.id, name }, res => {
                if (res.issuccess == 1) {
                    //   alert('修改成功')
                    this.freshlist()
                } else {
                    alert(res.msg)
                }
            })
        }

        // 
    }
    tosub(x) {
        window.location.href = "./dz_subcate.html?id=" + x.id + "&name=" + x.name;
    }
    // 排序
    addmoban() {
        if (this.state.showmoban) {
            //保存
            this.savemoban()

        } else {
            let moban = {
                cp: [
                    { width: 0, height: 0, deep: 0, singleprice: 0 }
                ],
                wj: [
                    { count: 0, singleprice: 0 }

                ],
                name: '',
                amount: 0
            }
            // let moban = {
            //     name:'123',
            //     wj:[
            //         {
            //           "count": "300",
            //           "singleprice": "15",
            //           "cid1": 84,
            //           "type": "WJ",
            //           "cname1": "国产品牌DTC铰链",
            //           "unit": "个"
            //         },
            //         {
            //           "count": "400",
            //           "singleprice": "15",
            //           "cid1": 84,
            //           "type": "WJ",
            //           "cname1": "国产品牌DTC铰链",
            //           "unit": "个"
            //         },
            //         {
            //           "count": "200",
            //           "singleprice": "48",
            //           "cid1": 113,
            //           "type": "WJ",
            //           "cname1": "文信长盒子拉手",
            //           "unit": "个"
            //         }
            //       ],

            //     cp:[
            //         {
            //           "width": "1000",
            //           "height": "1000",
            //           "deep": 0,
            //           "singleprice": "1000",
            //           "cid1": 78,
            //           "type": "CP",
            //           "cname1": "门板 | 柜体",
            //           "unit": "平方"
            //         },
            //         {
            //           "width": "2000",
            //           "height": "2000",
            //           "deep": 0,
            //           "singleprice": "798",
            //           "cid1": 50,
            //           "type": "CP",
            //           "cname1": "门板国产欧松板 | 柜体国产欧松板",
            //           "unit": "平方"
            //         },
            //         {
            //           "width": "3000",
            //           "height": "32000",
            //           "deep": 0,
            //           "singleprice": "880",
            //           "cid1": 41,
            //           "type": "CP",
            //           "cname1": "开放格（福人）",
            //           "unit": "平方"
            //         }
            //       ],
            // }



            this.setState({ moban, showmoban: !0 })
        }





    }

    addline(index, type, iindex) {

        if (this.state.input_name == '') {
            alert('请输入业主地址')
        } else {
            let { exportlist } = this.state,newitem={cname: '', count: '',cid1:0, cname1: "请选择", type, id: 0, width: '', height: '', deep: '', singleprice: '' }
            // exportlist[index]['items'][type == 'CP' ? 'cp' : 'wj'].push({ count: 0, type, id: 0, width: 0, height: 0, deep: 0, singleprice: 0 })
            
            console.log(newitem,'newitemnewitem--addline');
           
            exportlist[index]['items'][type == 'CP' ? 'cp' : 'wj'].splice(iindex + 1, 0, newitem)
           
            console.log(exportlist[index]['items'][type == 'CP' ? 'cp' : 'wj'], 'addline');


            // console.log(res,'addline-resa');

            //  this.setState({exportlist})
            this.save(exportlist)
        }
    }

    removeline(i, oi, t) {
        console.log({ i, oi, t }, 'removeline');
        let { exportlist } = this.state, items = exportlist[i]['items'][t == 'CP' ? 'cp' : 'wj'];
        if (items.length == 1) {
            items.push({ count: '', type: t, id: 0, width: '', height: '', deep: '', singleprice: '' })
        } else {
            items.splice(oi, 1)
        }
        exportlist[i]['items'][t == 'CP' ? 'cp' : 'wj'] = items
        // this.setState({exportlist})
        this.save(exportlist)

        //每次删除都要重新设置一边oindex


        //    let list = this.state.exportlist[i]['items'].filter(x=>{return x.type==t})
        //   //  let {moban} = this.state

        //     if(e==0){
        //         moban.cp.splice(i,1)
        //     }else{
        //         moban.wj.splice(i,1)
        //     }
        //     // let {moban} = this.state,data = [{}]
        //     // moban[`${e==0?'cp':'wj'}`].push(data)
        //      this.setState({moban})
    }




    // 删除
    del(e, cid) {
        this.setState({ delid: e, newcid: cid }, () => {
            $('#myModal').modal('toggle');
        })
    }

    delroom(index) {
        var b = confirm('确定要删除房间吗')
        if (b) {
            let { exportlist } = this.state
            exportlist.splice(index, 1)
            this.save(exportlist)
        }
    }



    confirmdel() {
        let { delid, start } = this.state
        delimg(delid, res => {
            if (res.issuccess == 1) {
                //  alert('删除成功')
                $('#myModal').modal('toggle');
                this.freshlist(start)
            } else {
                $('#myModal').modal('toggle');
                alert(res.msg);
            }
        })
    }

    closemodal() {
        $('.modal1').hide()
    }

    inputchange(prop, e) {
        this.setState({ [prop]: e.target.value })
    }
    confirm() {
        let { name, subtitle } = this.state, err = '';
        if (name.length == 0) err = '请输入名称'
        dz_project_aoe({ name, subtitle }, res => {
            $('.modal1').hide()
            if (res.issuccess == 1) {
                //   alert('提交成功')
                this.freshlist()
            }
        })
    }

    toitem(id) {
        window.location.href = './dz_item.html?id=' + id
    }

    // selectchange(e){
    //     this.setState({selectroomid:e.target.value})
    // }

    selectchange(ei, t, index, e) {
        //  if(this.state.detail.pool!='BJ') return
        

        let { value } = e.target, { exportlist, categorylist } = this.state, tname = t == 'CP' ? 'cp' : 'wj'
        if (value == '-1') {
            exportlist[ei]['items'][tname][index]['cid1'] = -1;
            exportlist[ei]['items'][tname][index]['type'] = ""
            exportlist[ei]['items'][tname][index]['cname1'] = "";
            exportlist[ei]['items'][tname][index]['singleprice'] = 0;
            exportlist[ei]['items'][tname][index]['unit'] = "";

        } else {
            let list = categorylist.filter(x => x.type == t == 'CP' ? 'GTCZ' : 'WJLB').reverse(), item = list.find(x => x.id == value), i = 0;
            //    console.log('here-selectchange', { ei, t, e, index, item });
            // if (id > 0) {
            //     i = exportlist[ei]['items'].findIndex(x => { return x.id == id })
            // } else {
            //     //自定义里的 
            //     // if(t=='WJLB'){
            //     //     index+=exportlist[ei]['items'].filter(x=>{return x.type=='CP'}).length
            //     // }
            //     i = exportlist[ei]['items'].findIndex(x => { return x.oindex == index })
            // }
            //console.log(i, 'selectchange--i');
            exportlist[ei]['items'][tname][index]['cid1'] = item.id;
            exportlist[ei]['items'][tname][index]['type'] = t
            exportlist[ei]['items'][tname][index]['cname1'] = item.name;
            exportlist[ei]['items'][tname][index]['singleprice'] = item.price;
            exportlist[ei]['items'][tname][index]['unit'] = item.unit;
            if (item.unit == '扇') {
                console.log(exportlist[ei]['items'][tname][index]['count'], 'countt');
                exportlist[ei]['items'][tname][index]['count'] = 1;

            }

        } 
        console.log('selectchange132',exportlist);


        this.setState({ exportlist }, () => {
            this.save(exportlist)
        })
    }


    selectchange1(ei, t, index, e) {
        //  if(this.state.detail.pool!='BJ') return

        console.log('here-selectchange1', { ei, t, e, index });
        let { value } = e.target, { exportlist, categorylist } = this.state, tname = 'cp'


        let item = categorylist.filter(x => x.type == t).find(x => x.id == value), i = 0;
        console.log('here-selectchange1', { ei, t, e, index, item });
        // if (id > 0) {
        //     i = exportlist[ei]['items'].findIndex(x => { return x.id == id })
        // } else {
        //     //自定义里的 
        //     // if(t=='WJLB'){
        //     //     index+=exportlist[ei]['items'].filter(x=>{return x.type=='CP'}).length
        //     // }
        //     i = exportlist[ei]['items'].findIndex(x => { return x.oindex == index })
        // }
        //console.log(i, 'selectchange--i');
        exportlist[ei]['items'][tname][index][t + "id"] = item ? item.id : 0;
        exportlist[ei]['items'][tname][index][t + "src"] = item ? item.imgurl : '';
        exportlist[ei]['items'][tname][index]['type'] = item ? t : ''
        exportlist[ei]['items'][tname][index][t + 'name'] = item ? item.name : '';
        // exportlist[ei]['items'][tname][index]['singleprice'] = item.price;
        // exportlist[ei]['items'][tname][index]['unit'] = item.unit;
        this.setState({ exportlist }, () => {
            this.save(exportlist)
        })
    }


    savemoban() {
        let { input_name } = this.state
        if (input_name == '') {
            alert('请输入业主地址')
            return
        } else {
            let { moban, exportlist } = this.state, data = {
                name: this.state.input_mbname,
                items: {
                    cp: [{ width: 0, height: 0, deep: 0, singleprice: 0 }]
                    , wj: [{ count: 0, singleprice: 0 }]
                }
            }
            exportlist.push(data)
            this.save(exportlist)


            this.setState({
                exportlist, moban: {
                    cp: [
                        { width: 0, height: 0, deep: 0, singleprice: 0 }
                    ],
                    wj: [
                        { count: 0, singleprice: 0 }

                    ],
                    name: '',
                    amount: 0
                }
            })
        }
    }

    export1() {
          let {exportlist} = this.state
            console.log(exportlist,'list111');
            let hasz = !1;
            exportlist.forEach(x1=>{
                x1.items.cp.forEach(x2=>{
                   if((Number(x2.count) * Number(x2.singleprice)).toFixed(2)==0){
                    hasz=!0
                   }
                })
                if(!hasz){
                    x1.items.wj.forEach(x2=>{
                        if((Number(x2.count) * Number(x2.singleprice)).toFixed(2)==0){
                         hasz=!0
                        }
                     })
                }
            })
            hasz = !1
            if(hasz){
                alert('细项不能为空')
            }else{
                this.setState({ showpage: !0, showbtn: !1, showeditprice: !1 }, () => {
                    window.print()
                })
                setTimeout(() => {
                    this.setState({ showpage: !1, showbtn: !0 })
                });
            }
       
    }

    export() {



        let { exportlist, detail } = this.state;

        let str = '总屋名称,' + detail.name
        //`${topname}\n${housename}\n产品类型,高,宽,深度,单价,数量,总价,单位,立面说明,门板材质/柜体材质\n`
        const jsonData = []
        let total = 0;
        let totalcount = 0;
        // <td className="tconter">{((Number(x.height)* Number(x.width))/1000000).toFixed(2)}</td>
        //                                    <td className="tconter">{(Number(x.singleprice)* (((Number(x.height)* Number(x.width))/1000000).toFixed(2))).toFixed(2)}</td>

        console.log(exportlist, 'exportlistexportlist');
        let haszero = false;
        exportlist.forEach(x => {
            
            str += `\n房间名称,${x.name}\n产品类型,高,宽,深度,数量,单位,单价,总价,立面说明,门板/柜体材质\n`
            x.items.filter(x => { return x.type == 'CP' }).forEach(y => {
                let zongjia_cp = (Number(y.count) * Number(y.singleprice)).toFixed(2)
                if(zongjia_cp==0){
                    haszero = !0
                }else{
                    str += `${y.cname},${y.height},${y.width},${y.deep},${y.count},${y.unit},${y.singleprice},${zongjia_cp},${y.lmsm},${y.cname1}\n`
                }
            })
            if(!haszero){
                str += `,,,平方总计,${x.cptotalcount},,金额合计,${x.cptotal}\n\n`
                str += `五金类型,高,宽,深度,数量,单位,单价,总价,立面说明,五金材质\n`
                x.items.filter(x => { return x.type == 'WJ' }).forEach(y => {
                    let zongjia_wj = (Number(y.count) * Number(y.singleprice)).toFixed(2)
                    if(zongjia_wj==0){
                        haszero = !0
                    }else{
                        str += `${y.cname},-,-,-,${y.count},${y.unit},${y.singleprice},${zongjia_wj},${y.lmsm},${y.cname1}\n`
                    }
                })
                if(!haszero){
                    str += `,,,,,,,,金额合计,${x.wjtotal}\n`
                    str += `总金额,${Math.round(Number(x.cptotal) + Number(x.wjtotal))}\n`
                    total = Math.round(Number(total) + Number(x.cptotal) + Number(x.wjtotal))
                }
                
            }
        })
        if(!haszero){
            str += '\n\n总价合计,' + total
            let uri = 'data:text/csv;charset=utf-8,\ufeff' + encodeURIComponent(str);
            //通过创建a标签实现
            let link = document.createElement("a");
            link.href = uri;
            //对下载的文件命名
            link.download = name + ".csv";
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
        }else{
            alert('有细项为0，请检查')
        }
    }


    addroom() {
        let { selectroomid, exportlist, totalamount } = this.state;
        if (Number(selectroomid) > 0) {
            dz_getprojectitemlist(selectroomid, res => {
                if (res.issuccess == 1) {
                    let { room, wj, cp } = res;
                    let wjtotal = 0, cptotal = 0, cptotalcount = 0, wjtotalcount = 0, amount = 0
                    wj.forEach(x => {
                        wjtotal = (Number(wjtotal) + (Number(x.singleprice) * Number(x.count))).toFixed(2)
                        wjtotalcount = (Number(wjtotalcount) + Number(x.count)).toFixed(2)
                    })
                    cp.forEach(x => {
                        cptotalcount = (Number(cptotalcount) + Number(x.count)).toFixed(2)
                        cptotal = (Number(cptotal) + (Number(x.singleprice) * Number(x.count))).toFixed(2)
                    })
                    amount = (Number(wjtotal) + (Number(cptotal))).toFixed(2)
                    totalamount = (Number(totalamount) + (Number(amount))).toFixed(2)
                    let item = { room, wjtotal, cptotal, cptotalcount, wjtotalcount, amount, wj, cp }
                    console.log(item, 'item');
                    exportlist.push(item)
                    console.log(exportlist, 'exportlist');
                    this.setState({ exportlist, totalamount })
                }
            })
        }
    }

    save(exportlist) {
        let { id, input_name } = this.state,that = this;
        if (input_name == '') {
            alert('请输入业主地址')
        } else {
            let data = { name: input_name, rawData: JSON.stringify(exportlist) }
            if (Number(id) > 0) data['id'] = id
            dz_projectdetail_editdata(data, res => {
                if (res.issuccess == 1) {
                    if (Number(id) > 0) {
                    } else {
                        this.setState({ id: res.id })
                    }
                    this.setState({ exportlist },()=>{
                        that.freshpriceitem()  
                    })

                    //alert('保存成功')
                    // if(ismoban){
                    //     window.location.href='./dz_newroom.html?id='+res.id
                    // }
                }
            })
        }

    }

    inputchange1(eindex, prop, val, tdindex, type) {
        // if(this.state.detail.pool!='BJ') return
        var value = prompt('请输入', val)
        console.log('inputchange1', { eindex, prop, val });
        if (value != val && value != '' && value != null) {
            let { exportlist } = this.state
            exportlist[eindex]['items'][type][tdindex][prop] = value
            this.setState({ exportlist }, () => {
                this.save(exportlist)
            })
            // if (id == -1) {
            //     //自定义内容
            //     console.log('自定义内容', { eindex, prop, val, tdindex });
            //     if (wjval == 'wj') {
            //         tdindex += exportlist[eindex]['items'].filter(x => { return x.type == 'CP' }).length
            //         // console.log(cpcount,'cpcountcpcount');
            //         //  exportlist[eindex]['items'][tdindex+cpcount][prop] = value
            //     }

            //     exportlist[eindex]['items'][tdindex][prop] = value

            // } else {
            //     let index = exportlist[eindex]['items'].findIndex(x => { return x.id == id })
            //     exportlist[eindex]['items'][index][prop] = value;
            // }


        }
    }

    // inputmobanchange1(prop, t, index, val) {

    //     // if(this.state.detail.pool!='BJ') return
    //     var value = prompt('请输入', val), { moban } = this.state
    //     if (value != val && value != '') {
    //         let tval = t == 0 ? 'cp' : 'wj'
    //         moban[tval][index][prop] = value;
    //         //  let {exportlist} = this.state,index = exportlist[eindex]['items'].findIndex(x=>{return x.id==id})
    //         this.setState({ moban })
    //     }
    // }




    selectfang(e) {
        console.log(e.target.value, 'edddd');
        let sel_fang = e.target.value
        this.setState({ sel_fang })
    }

    addfangjian() {
        let { sel_fang, exportlist, input_name } = this.state;
        console.log(sel_fang, 'sel_fang');
        if (sel_fang == -1) {
            alert('请选择房型')
        } else if (input_name == '') {
            alert('请输入业主地址')
        } else {


            dz_getroombyid(sel_fang, res => {
                if (res.issuccess == 1) {
                    let { data } = res, rawData = JSON.parse(decodeurl(data.rawData))
                    let cptotalcount = 0, cptotal = 0, wjtotal = 0, roomdata = { items: { cp: [], wj: [] } };
                    console.log();
                    roomdata['name'] = data.name
                    console.log(rawData, 'rawDatarawData');

                    if (rawData.cp) {
                        rawData.cp.forEach(x => {
                            roomdata['items']['cp'].push(x)
                            cptotalcount += Number(x.count)
                            cptotal += (Number(x.count) * Number(x.singleprice))

                        })
                    } else if (rawData.items) {
                        rawData.items.cp.forEach(x => {
                            roomdata['items']['cp'].push(x)
                            cptotalcount += Number(x.count)
                            cptotal += (Number(x.count) * Number(x.singleprice))

                        })
                    }

                    if (rawData.wj) {
                        rawData.wj.forEach(x => {
                            roomdata['items']['wj'].push(x)
                            wjtotal += (Number(x.count) * Number(x.singleprice))
                        })
                    } else if (rawData.items) {
                        rawData.items.wj.forEach(x => {
                            roomdata['items']['wj'].push(x)
                            wjtotal += (Number(x.count) * Number(x.singleprice))
                        })
                    }



                    roomdata['cptotalcount'] = Number(cptotalcount).toFixed(2)
                    roomdata['cptotal'] = Number(cptotal).toFixed(2)
                    roomdata['wjtotal'] = Number(wjtotal).toFixed(2)
                    roomdata['amount'] = (Number(wjtotal) + Number(cptotal)).toFixed(2)
                    exportlist.push(roomdata)
                    this.setState({ exportlist })
                    this.save(exportlist)

                }

                // if (list.length > 0) {
                //     let roomdata = {items:{cp:[],wj:[]}}

                //     list.forEach(item => {

                //         data['name'] = item.name
                //         item.items.forEach(x => {
                //             if (x.type == 'CP') {
                //                 data['items']['cp'].push(x)
                //                 cptotalcount += Number(x.count)
                //                 cptotal += (Number(x.count) * Number(x.singleprice))
                //             } else {
                //                 data['items']['wj'].push(x)
                //                 wjtotal += (Number(x.count) * Number(x.singleprice))
                //             }
                //         })
                //         data['cptotalcount'] = Number(cptotalcount).toFixed(2)
                //         data['cptotal'] = Number(cptotal).toFixed(2)
                //         data['wjtotal'] = Number(wjtotal).toFixed(2)
                //         data['amount'] = (Number(wjtotal) + Number(cptotal)).toFixed(2)
                //         //  totalamount+=Number(wjtotal)+Number(cptotal)
                //         exportlist.push(data)
                //     })

                //     console.log(exportlist, 'addfangjian');


                // }
            })
        }
    }

    select1(e) {
        console.log(e.target.value, 'eee');
        // let {categorylist} = this.state,,list = categorylist.filter(x=>x.type==value).reverse()
        let { pricearr } = this.state, { value } = e.target, pricelist = pricearr[value];
        console.log(pricelist, 'pricelist'); 
        this.setState({ pricelist, select1id: value })

        // exportlist.forEach(x=>{
        //     x.items.cp.forEach(y => {
        //         if(y.cid){

        //         }
        //     });
        // })
        // console.log(exportlist,'exportlist');


        //  this.setState({pricelist:list,select1id:value })

    }

    select2(e) {
        console.log(e.target.value, 'select2');
        let { categorylist } = this.state, { value } = e.target, item = categorylist.find(x => x.id == value);
        console.log(item, 'item');
        this.setState({ priceitem: item, select_priceid: value })
    }

    select3(e) {
        console.log(e.target.value, 'select2');
        let { categorylist, priceitem } = this.state, { value } = e.target, item = categorylist.find(x => x.id == value);
        console.log(item, 'item');
        console.log(priceitem, 'priceitem');
        // priceitem.price = item.price
        // priceitem.name = item.name
        // priceitem.id = item.id

        this.setState({ price_choseitem: item, priceitem, select_pricechoseid: value })
    }

    inputchangeprice() {
        let { exportlist, priceitem, price_choseitem } = this.state;
        console.log({price_choseitem,priceitem},'inputchangeprice--item查看');
        if(!price_choseitem){
            price_choseitem = priceitem
        }else if (JSON.stringify(price_choseitem)){ 
           // price_choseitem = priceitem
        } 

        console.log(price_choseitem,'price_choseitemprice_choseitem');

        exportlist.forEach(x => {
            if (priceitem.type == 'GTCZ') {
                x.items.cp.forEach(y => { 
                    if (y.cid1 == priceitem.id) {
                        y.singleprice = priceitem.price
                        y.cname1 = price_choseitem.name
                        y.unit = price_choseitem.unit
                        y.cid1 = price_choseitem.id
                    }
                })
            } else {
                x.items.wj.forEach(y => {
                    if (y.cid1 == priceitem.id) {
                        y.singleprice = priceitem.price
                        y.cname1 = price_choseitem.name
                        y.unit = price_choseitem.unit
                        y.cid1 = price_choseitem.id
                    }
                })
            }
        })
        // this.setState({exportlist})
        this.save(exportlist)
        // this.setState({select1id:-1}
      
    }



    pricechange(t, e) {
        let { priceitem } = this.state, { value } = e.target
        if (t == 'price') {
            if (isNaN(value)) {
                alert('价格输入有误')
            } else {
                priceitem.price = value;
                this.setState({ priceitem })
            }
        } else {
            priceitem[t] = value;
            // let 
            this.setState({ priceitem })
            // if(value){
            //     alert('价格输入有误')
            // }else{
            //     priceitem.price = value;
            //     this.setState({priceitem})
            // }

        }
    }


   

    freshpriceitem() {
        let { exportlist, categorylist } = this.state;
        this.formatlist(exportlist, categorylist)
        this.setState({ select1id: -1, price_choseitem: {}, priceitem: {}, select_pricechoseid: 0, select_priceid: 0 })

    }

    updown(exportindex, b, c, d) {
        //a exportindex,
        //b WJ,
        //b index,
        //d  0上移动 1下移
        let { exportlist } = this.state, items = exportlist[exportindex]['items'][b == 'WJ' ? 'wj' : 'cp'];
        if (d == 0) {
            if (items.length > 1 && c != 0) {
                items = swapItems(items, c, c - 1)
                this.save(exportlist)
            }
        } else {
            if (items.length > 1 && c != items.length - 1) {
                items = swapItems(items, c, c + 1)
                this.save(exportlist)
            }
        }

        //  console.log({exportindex,b,c,d,item},'updown');
    }



    changeroomname(index, def) {
        var value = prompt('请输入', def)
        // console.log('inputchange1', { eindex, prop, val });
        if (value != def && value != '' && value != null) {
            let { exportlist } = this.state
            exportlist[index]['name'] = value
            this.setState({ exportlist })
            this.save(exportlist)
        }
    }

    blur() {
        // console.log('blurrrr');
        let that = this
        if (this.state.needsave) {
            that.setState({ needsave: !1 }, () => {
                that.save(this.state.exportlist)
            })
        }
    }

    newinputchange(eindex, prop, tdindex, type, val, e) {

        let { exportlist } = this.state, { value } = e.target
        if (value != val) {
            if (['width', 'height', 'deep', 'singleprice', 'count'].indexOf(prop) > -1) {
                if (isNaN(value)) {
                    alert('输入正确的数字')
                } else {
                    exportlist[eindex]['items'][type][tdindex][prop] = e.target.value
                    this.setState({ exportlist, needsave: !0 })
                }
            } else {
                exportlist[eindex]['items'][type][tdindex][prop] = e.target.value
                this.setState({ exportlist, needsave: !0 })
            }
            //console.log({eindex, prop, tdindex, type,e:e.target.value});
        }

    }

 
    render() {
        var { showpage1, categorylist, select_pricechoseid, showbtn, input_name, select_priceid,pricearr, select1id, showeditprice, sel_fang, showpage, fangjianhtml, moban, id, cate_MBXHhtml, cate_LSFShtml, cate_GTXHhtml, showmoban, input_mbname, detail, name, exportlist, totalamount, cate_WJLBhtml, roomhtml, selectroomid, cate_GTCZhtml } = this.state;
        console.log({ exportlist }, 'render--exportlist');
        console.log(select1id, 'select1idselect1idselect1id');
 
        
        let moban_amount = 0,pricelist =select1id==-1?[]:pricearr[select1id] ;
        moban.cp.forEach(x => {
            moban_amount += Math.round(((Number(x.height) * Number(x.width)) / 1000000) * Number(x.singleprice))
        })
        moban.wj.forEach(x => {
            moban_amount += Math.round(Number(x.count) * Number(x.singleprice))
        })
        moban.amount = moban_amount
        //  console.log(exportlist, 'exportlistexportlist');

        if (exportlist.length > 0) {
            exportlist.forEach(item => {
                let cptotalcount = 0, cptotal = 0, wjtotal = 0;

                item.items.cp.forEach(x => {
                    x.count = (x.unit == '米' ? (Number(x.width) / 1000) : ((Number(x.height) * Number(x.width)) / 1000000)) * this.getxs(x.deep)
                    if (x.unit == '扇') { x.count = 1 }
                    cptotalcount += Number(x.count)
                    cptotal = Math.round(Number(cptotal) + (Number(x.count) * Number(x.singleprice)))
                })
                item.items.wj.forEach(x => {
                    if (x.unit == '扇') { x.count = 1 }
                    wjtotal = Math.round(Number(wjtotal) + (Number(x.count) * Number(x.singleprice)))
                })
                item['cptotalcount'] = Number(cptotalcount).toFixed(2)
                item['cptotal'] = cptotal
                item['wjtotal'] = wjtotal
                item['amount'] = Math.round(Number(wjtotal) + Number(cptotal))
                totalamount = Math.round(Number(totalamount) + Number(wjtotal) + Number(cptotal))
            })
        }
        return (

            <div className="breadLinebox">
                <div style={{ display: showpage1 ? 'none' : '' }}>
                    <div style={{ display: !showbtn ? 'none' : '' }} className="content">
                        <input placeholder="请输入业主地址" allowClear value={input_name} onChange={this.inputchange.bind(this, 'input_name')} className="input" />
                    </div>
                    <div style={{ display: !showbtn ? '' : 'none', border: 'none', padding: '0', fontSize: '18px', textAlign: 'center' }} className="content">
                        {input_name}
                    </div>

                    <div style={{ display: !showbtn ? 'none' : '' }} className="selfang">
                        <p onClick={this.savemoban.bind(this)} className="btn">新增房间</p>
                        <p className="p1">选择房型</p>
                        <select value={sel_fang} onChange={this.selectfang.bind(this)}>  {fangjianhtml} </select>
                        <p onClick={this.addfangjian.bind(this)} className="btn">添加模板房型</p>
                        <p onClick={() => { window.location.href = './dz_newroomdetail.html?id=' + id }} className="btn">用户花色</p>
                        <p className="btn" style={{ 'cursor': 'pointer' }} onClick={() => { this.setState({ showeditprice: !0 }) }}>调整</p>
                        <p className="btn" style={{ 'cursor': 'pointer' }} onClick={() => {
                            this.export1()
                        }}>打印</p>
                        <p onClick={() => { window.location.href = './dz_main.html' }} className="btn">返回</p>
                    </div>
                    {
                        showeditprice ?
                            <div style={{ display: showeditprice ? '' : 'none' }} className="pricearea">
                                <p className="p1">选择类型 </p>
                                <select value={select1id} onChange={this.select1.bind(this)}>
                                    <option value={'-1'}>请选择 </option>
                                    <option value={'GT'}>柜体材质 </option>
                                    <option value={'WJ'}>五金类别 </option>
                                </select>
                                {
                                    select1id != '-1' ?
                                        <div className="p35">
                                            <select value={select_priceid} onChange={this.select2.bind(this)}>
                                                <option value={'-1'}>请选择 </option>
                                                {
                                                    pricelist.map((x, i) => {
                                                        return (
                                                            <option value={x.id}>{x.name} </option>
                                                        )
                                                    })
                                                }
                                            </select>

                                        </div>
                                        : null

                                }
                                <div className="p36" style={{ display: select1id != '-1' ? '' : 'none' }}>

                                    {
                                        select1id != '-1' ?
                                            <div className="p35">
                                                <select value={select_pricechoseid} onChange={this.select3.bind(this)}>
                                                    <option value={'-1'}>请选择 </option>
                                                    {
                                                        categorylist.filter(x => x.type == (select1id == 'GT' ? 'GTCZ' : 'WJLB')).reverse().map((x, i) => {
                                                            return (
                                                                <option value={x.id}>{x.name} </option>
                                                            )
                                                        })
                                                    }
                                                </select>

                                            </div>
                                            : null

                                    }


                                    <input type="text" value={this.state.priceitem.price} onChange={this.pricechange.bind(this, 'price')} />
                                    <p className="pricebtn" onClick={this.inputchangeprice.bind(this)}>修改</p>
                                </div>

                            </div>
                            : null

                    }

                    <div className='content_wrap panel-default content_wrap ' style={{ padding: showpage ? '0' : '10px 30px' }}>


                        <div style={{ border: showpage ? 'none' : '', padding: showpage ? '0' : '10px 30px' }} className="content form">
                            {/* <div style={{display:clicknew?"":"none"}} id="div"> */}
                            <div className="titlet">{this.state.detail.name}</div>
                            {
                                exportlist.map((x, exportindex) => {
                                    return (
                                        <div>

                                            <div style={{ border: showpage ? 'none' : '', margin: showpage ? '0' : '', padding: showpage ? '0' : '10px 30px' }} className="content form">
                                                <div className="deldiv">
                                                    <p onClick={this.changeroomname.bind(this, exportindex, x.name)}>{x.name || '点此输入房间名称'}</p>
                                                    <p style={{ display: !showbtn ? 'none' : '' }} onClick={this.delroom.bind(this, exportindex)} className="delroom">删除</p>
                                                </div>
                                                <table className="tab">
                                                    <thead>
                                                        <tr>
                                                            {/* <th className="minwidth tconter"><img src="./src/notselection.png"/></th> */}

                                                            <th style={{ display: showpage ? 'none' : '' }} className="tconter td0">序号</th>
                                                            <th className="tconter td1"> <div >产品类型</div></th>
                                                            <th className="tconter td2"><div >宽度</div></th>
                                                            <th className="tconter td2"><div >高度</div></th>
                                                            <th className=" tconter td2"><div >深度</div></th>
                                                            <th className=" tconter td2"><div >数量</div></th>
                                                            <th className=" tconter td2"><div >单位</div></th>
                                                            <th className=" tconter td2"><div >单价</div></th>
                                                            <th className=" tconter td2"><div >总价</div></th>
                                                            <th className=" tconter td1"><div >立面说明</div></th>
                                                            {/* <th className=" tconter td3"><div className="td1">拉手方式</div></th> */}
                                                            <th className=" tconter td3"><div className="td3">门板/柜体材质</div></th>
                                                            <th className=" tconter td3"><div className="td1">门板型号</div></th>
                                                            <th className=" tconter td3"><div className="td1">柜体型号</div></th>
                                                            <th style={{ display: showpage ? 'none' : '' }} className="tconter td1"><div className="td1">操作</div></th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        {

                                                            x.items.cp.map((item_cp, index) => {
                                                                let xs = this.getxs(item_cp.deep)
                                                                let count = (item_cp.unit == '米' ? (Number(item_cp.width) / 1000) : ((Number(item_cp.height) * Number(item_cp.width)) / 1000000)) * xs
                                                                if (item_cp.unit == '扇') { count = 1 }
                                                                return (
                                                                    <tr key={index}>
                                                                        {/* <td className="minwidth tconter"><img src="./src/notselection.png"/></td>  */}
                                                                        {/* <td className="tconter">{x.state=="0"?"显示":"隐藏"}</td>  */}
                                                                        <td style={{ display: showpage ? 'none' : '' }} className="tconter td0">{index + 1}</td>
                                                                        {/* <td onClick={this.inputchange1.bind(this, exportindex, 'cname', item_cp.cname, index, 'cp')} className="tconter td1">
                                                                            <div>{item_cp.cname}</div>
                                                                        </td> */}

                                                                        <td className="tconter td1">
                                                                            <div className="td2">
                                                                            <input type="text" value={item_cp.cname || ""} onBlur={this.blur.bind(this)} onChange={this.newinputchange.bind(this, exportindex, 'cname', index, 'cp', item_cp.cname)} />
                                                                            </div>
                                                                            {/* <div>{}</div> */}
                                                                        </td>

                                                                        {/* <td onClick={this.inputchange1.bind(this, exportindex, 'width', item_cp.width, index, 'cp')} className="tconter td2">
                                                                            <div >{item_cp.width}</div>
                                                                        </td> */}
                                                                        <td className="tconter td2">
                                                                        <div className="td2">
                                                                            <input type="text" value={item_cp.width} onBlur={this.blur.bind(this)} onChange={this.newinputchange.bind(this, exportindex, 'width', index, 'cp', item_cp.width)} />
                                                                            </div>
                                                                        </td>

                                                                        <td className="tconter td2">
                                                                            <input type="text" value={item_cp.height} onBlur={this.blur.bind(this)} onChange={this.newinputchange.bind(this, exportindex, 'height', index, 'cp', item_cp.height)} />

                                                                        </td>

                                                                        <td className="tconter td2">
                                                                            <input type="text" value={item_cp.deep} onBlur={this.blur.bind(this)} onChange={this.newinputchange.bind(this, exportindex, 'deep', index, 'cp', item_cp.deep)} />
                                                                        </td>


                                                                        {/* <td onClick={this.inputchange1.bind(this, exportindex, 'height', item_cp.height, index, 'cp')} className="tconter td2">
                                                                            <div >{item_cp.height}</div>
                                                                        </td>
                                                                        <td onClick={this.inputchange1.bind(this, exportindex, 'deep', item_cp.deep, index, 'cp')} className="tconter td2">
                                                                            <div >{item_cp.deep}</div>
                                                                        </td> */}
                                                                        {/* <td className="tconter td2">{
                                                                            <div >{count.toFixed(2)}</div>
                                                                        }</td> */}

                                                                        <td className="tconter td2">
                                                                            <input type="text" value={item_cp.count.toFixed(2)} onBlur={this.blur.bind(this)} onChange={this.newinputchange.bind(this, exportindex, 'count', index, 'cp', item_cp.count.toFixed(2))} />
                                                                        </td>

                                                                        <td className="tconter td2">
                                                                            <div >{item_cp.unit}</div>
                                                                        </td>

                                                                        <td className="tconter td2">
                                                                            <input type="text" value={item_cp.singleprice} onBlur={this.blur.bind(this)} onChange={this.newinputchange.bind(this, exportindex, 'singleprice', index, 'cp', item_cp.singleprice)} />
                                                                        </td>
                                                                        {/* <td onClick={this.inputchange1.bind(this, exportindex, 'singleprice', item_cp.singleprice, index, 'cp')} className="tconter td2">
                                                                            <div className="td2">{item_cp.singleprice}</div>
                                                                        </td> */}
                                                                        <td className="tconter td2">
                                                                            <div > {Math.round(Number(item_cp.singleprice) * count)}</div>

                                                                        </td>
                                                                        {/* <td onClick={this.inputchange1.bind(this, exportindex, 'lmsm', item_cp.lmsm, index, 'cp')} className="tconter td3">
                                                                            <div >{item_cp.lmsm}</div></td> */}
                                                                        <td className="tconter td2">
                                                                            <input type="text" value={item_cp.lmsm} onBlur={this.blur.bind(this)} onChange={this.newinputchange.bind(this, exportindex, 'lmsm', index, 'cp', item_cp.lmsm)} />

                                                                        </td>

                                                                        {/* <td style={{ display: showpage ? 'none' : '' }} className="tconter td3 sel">
                                                                            <div className="td1">
                                                                                <select value={item_cp.LSFSid} onChange={this.selectchange1.bind(this, exportindex, 'LSFS', index)}>
                                                                                    <option value={-1}>请选择 </option>
                                                                                    {
                                                                                        categorylist.filter(x => x.type == 'LSFS').reverse().map((x, i) => {
                                                                                            return (
                                                                                                <option key={i} value={x.id}>{x.name} </option>
                                                                                            )
                                                                                        })

                                                                                    }

                                                                                </select>
                                                                            </div>
                                                                        </td> */}
                                                                        {/* <td style={{ display: showpage ? '' : 'none' }} className="tconter td3"><div className="td1">
                                                                            {item_cp.LSFSname}
                                                                        </div>
                                                                        </td> */}

                                                                        <td style={{ display: showpage ? 'none' : '' }} className="tconter td3">
                                                                            <div className="td3">
                                                                                {/* {
                                                                            console.log(item_cp.cid1,'item_cp.cid1')
                                                                        } */}


<antd.Select optionFilterProp='label'  showSearch value={item_cp.cname} onChange={this.selectchange.bind(this, exportindex, 'CP', index)}   >
<option value={-1}>请选择 </option>
                                                                                    {
                                                                                        categorylist.filter(x => x.type == 'GTCZ').reverse().map((x, i) => {
                                                                                            return (
                                                                                                <option label={x.name} key={i} value={x.id}>{x.name} </option>
                                                                                            )
                                                                                        })

                                                                                    } 
                                                                                </antd.Select>


                                                                                {/* <select value={item_cp.cid1} onChange={this.selectchange.bind(this, exportindex, 'CP', index)}>
                                                                                    <option value={-1}>请选择 </option>
                                                                                    {
                                                                                        categorylist.filter(x => x.type == 'GTCZ').reverse().map((x, i) => {
                                                                                            return (
                                                                                                <option key={i} value={x.id}>{x.name} </option>
                                                                                            )
                                                                                        })

                                                                                    } </select> */}

                                                                            </div>
                                                                        </td>
                                                                        <td style={{ display: showpage ? '' : 'none' }} className="tconter td3">
                                                                            <div className="td3">
                                                                                {item_cp.cname1 == -1 ? '' : item_cp.cname1}
                                                                            </div>
                                                                        </td>
                                                                        <td style={{ display: showpage ? 'none' : '' }} className="tconter td3">
                                                                            <div className="td1">
                                                                                <select value={item_cp.MBXHid} onChange={this.selectchange1.bind(this, exportindex, 'MBXH', index)}>
                                                                                    <option value={-1}>请选择 </option>
                                                                                    {
                                                                                        categorylist.filter(x => x.type == 'MBXH').reverse().map((x, i) => {
                                                                                            return (
                                                                                                <option key={i} value={x.id}>{x.name} </option>
                                                                                            )
                                                                                        })

                                                                                    } </select>
                                                                            </div>
                                                                        </td>
                                                                        <td style={{ display: showpage ? '' : 'none' }} className="tconter td3">
                                                                            <div className="td1">
                                                                                {item_cp.MBXHname || ''}
                                                                            </div>
                                                                        </td>

                                                                        <td style={{ display: showpage ? 'none' : '' }} className="tconter td3">
                                                                            {/* <div className="td1"> */}
                                                                            <select value={item_cp.GTXHid} onChange={this.selectchange1.bind(this, exportindex, 'GTXH', index)}>
                                                                                <option value={-1}>请选择 </option>
                                                                                {
                                                                                    categorylist.filter(x => x.type == 'GTXH').reverse().map((x, i) => {
                                                                                        return (
                                                                                            <option key={i} value={x.id}>{x.name} </option>
                                                                                        )
                                                                                    })

                                                                                } </select>
                                                                            {/* </div> */}
                                                                            {/* <img  style={{display:item_cp.GTXHsrc?'':'none'}}  src={IMGSOURCE+item_cp.GTXHsrc}/> */}
                                                                        </td>
                                                                        <td style={{ display: showpage ? '' : 'none' }} className="tconter td3">
                                                                            <div className="td1">
                                                                                {item_cp.GTXHname}

                                                                            </div>
                                                                        </td>


                                                                        {/* <td className="tconter w80"> {item_cp.cname1}</td> */}
                                                                        <td style={{ display: showpage ? 'none' : '' }} className="tconter btnn">
                                                                            <p onClick={this.addline.bind(this, exportindex, 'CP', index)}>添加一行</p>
                                                                            <p onClick={this.updown.bind(this, exportindex, 'CP', index, 0)}>上移</p>
                                                                            <p onClick={this.updown.bind(this, exportindex, 'CP', index, 1)}>下移</p>
                                                                            <p onClick={this.removeline.bind(this, exportindex, index, 'CP')}>移除</p>
                                                                        </td>

                                                                    </tr>
                                                                )

                                                            })
                                                        }
                                                    </tbody>
                                                </table>
                                                {/* <div className="tongji">
                                                <div>
                                                <p> 数量合计：{x.cptotalcount}</p>
                                                <p> 合计：{x.cptotal}</p>
                                                </div>
                                                    
                                               
                                            </div> */}


                                                <table className="tab">
                                                    <thead>
                                                        <tr>
                                                            {/* <th className="minwidth tconter"><img src="./src/notselection.png"/></th> */}

                                                            <th style={{ display: showpage ? 'none' : '' }} className="tconter td0">序号</th>
                                                            <th className="tconter td1"><div  >五金类别</div></th>
                                                            <th className=" tconter td2"><div  >宽度</div></th>
                                                            <th className=" tconter td2"><div  >高度</div></th>
                                                            <th className=" tconter td2"><div  >深度</div></th>
                                                            <th className=" tconter td2"><div  >数量</div></th>
                                                            <th className=" tconter td2"><div  >单位</div></th>
                                                            <th className=" tconter td2"><div  >单价</div></th>
                                                            <th className=" tconter td2"><div  >总价</div></th>
                                                            <th className=" tconter td1"><div  >立面说明</div></th>
                                                            <th className=" tconter td3"><div  >备注</div></th>
                                                            <th className=" tconter td3"><div  ></div></th>
                                                            <th className=" tconter td3"><div  ></div></th>
                                                            <th className=" tconter td3"><div  ></div></th>
                                                            <th style={{ display: showpage ? 'none' : '' }} className="cz tconter"><div className="td1"></div>操作</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        {
                                                            x.items.wj.map((item_cp, i) => {
                                                                return (
                                                                    <tr key={i}>
                                                                        {/* <td className="minwidth tconter"><img src="./src/notselection.png"/></td>  */}
                                                                        {/* <td className="tconter">{x.state=="0"?"显示":"隐藏"}</td>  */}
                                                                        <td style={{ display: showpage ? 'none' : '' }} className="tconter td0">{i + 1}</td>
                                                                        {/* <td className="tconter w80">
                                                                    {item_cp.cname1}
                                                                    </td> */}
                                                                        <td style={{ display: showpage ? 'none' : '' }} className="tconter td1">

                                                                                <select value={item_cp.cid1} onChange={this.selectchange.bind(this, exportindex, 'WJ', i)}>
                                                                                    <option value={-1}>请选择 </option>
                                                                                    {
                                                                                        categorylist.filter(x => x.type == 'WJLB').reverse().map((x, i) => {
                                                                                            return (
                                                                                                <option key={i} value={x.id}>{x.name} </option>
                                                                                            )
                                                                                        })

                                                                                    } </select>


                                                                            {/*    <div className="td1">
                                                                             {this.state.antdhtml} */}
                                                                            {/* <antd.Select showSearch value={item_cp.cid1} style={{ width: "100px" }} onChange={this.selectchange.bind(this, exportindex, 'WJ', i)} >
                                                                                <option value={-1}>请选择 </option>
                                                                                    {
                                                                                        categorylist.filter(x => x.type == 'WJLB').reverse().map((x, i) => {
                                                                                            return(
                                                                                                        // <option key={i} value={x.id}>{x.name} </option>
                                                                                                        <antd.Select.Option value={y.id}>{y.name} </antd.Select.Option>
                                                                                            )
                                                                                            })
                                                                                       
                                                                                    
                                                                                    
                                                                                    }
                                                                                </antd.Select> 

                                                                            </div>*/}

                                                                        </td>
                                                                        <td style={{ display: showpage ? '' : 'none' }} className="tconter td2">
                                                                            <div className="td1">
                                                                                {item_cp.cname1 || ''}

                                                                            </div>
                                                                        </td>
                                                                        <td className="tconter td2">
                                                                            <div className="td2">
                                                                                -
                                                                            </div>
                                                                        </td>
                                                                        <td className="tconter td2"><div className="td2"><input type="text" value={'-'} /></div></td>
                                                                        <td className="tconter td2"><div className="td2">-</div></td>
                                                                        {/* <td onClick={this.inputchange1.bind(this, exportindex, 'count', item_cp.count, i, 'wj')} className="tconter"><div className="td2">
                                                                            {item_cp.count}
                                                                        </div></td> */}

                                                                        <td className="tconter td2">
                                                                            <input type="text" value={item_cp.count} onBlur={this.blur.bind(this)} onChange={this.newinputchange.bind(this, exportindex, 'count', i, 'wj', item_cp.count)} />
                                                                        </td>
                                                                        <td className="tconter td2"><div className="td2">{item_cp.unit}</div></td>
                                                                        {/* <td onClick={this.inputchange1.bind(this, exportindex, 'singleprice', item_cp.singleprice, i, 'wj')} className="tconter td2"><div className="td2">{item_cp.singleprice}</div></td> */}

                                                                        <td className="tconter td2">
                                                                            <input type="text" value={item_cp.singleprice} onBlur={this.blur.bind(this)} onChange={this.newinputchange.bind(this, exportindex, 'singleprice', i, 'wj', item_cp.singleprice)} />
                                                                        </td>

                                                                        <td className="tconter"><div className="td2">{Math.round(Number(item_cp.singleprice) * Number(item_cp.count))}</div></td>
                                                                        <td onClick={this.inputchange1.bind(this, exportindex, 'lmsm', item_cp.lmsm, i, 'wj')} className="tconter w80"><div className="td1">

                                                                            {item_cp.lmsm}
                                                                        </div>
                                                                        </td>
                                                                        <td className="tconter td3"> <div className="heng">
                                                                            {item_cp.cname}
                                                                        </div>
                                                                        </td>
                                                                        <td className="tconter td3"><div className="heng">-</div></td>
                                                                        <td className="tconter td3"><div className="heng">-</div></td>
                                                                        <td className="tconter td3"><div className="heng">-</div></td>
                                                                        <td style={{ display: showpage ? 'none' : '' }} className="tconter btnn ">


                                                                            <p onClick={this.addline.bind(this, exportindex, 'WJ', i)}>添加一行</p>
                                                                            <p onClick={this.updown.bind(this, exportindex, 'WJ', i, 0)}>上移</p>
                                                                            <p onClick={this.updown.bind(this, exportindex, 'WJ', i, 1)}>下移</p>
                                                                            <p onClick={this.removeline.bind(this, exportindex, i, 'WJ')}>移除</p>
                                                                        </td>
                                                                    </tr>
                                                                )

                                                            })
                                                        }
                                                    </tbody>
                                                </table>
                                                {/* <div className="tongji">
                                                <div>
                                                <p> 合计：{x.wjtotal}</p>
                                                </div>

                                            </div> */}
                                                <div className="tongji he">
                                                    <p>合计金额：{x.amount}</p>
                                                </div>

                                            </div>
                                        </div>

                                    )
                                })
                            }


                            <div className="tabletit" >

                                {/* <select value={selectroomid} onChange={this.selectchange.bind(this)}>{roomhtml} </select>

    <p className="add" style={{'cursor':'pointer'}} onClick={this.addroom.bind(this)}>添加</p> */}

                                <p>总金额：{totalamount}</p>


                                <div className="gysm">{$.cookie('gysm') == 'null' ? '' : $.cookie('gysm')}</div>

                                <div style={{ display: showbtn ? '' : 'none' }}>
                                    <p className="add" style={{ 'cursor': 'pointer' }} onClick={this.export1.bind(this)}>打印</p>

                                    <p className="add" style={{ 'cursor': 'pointer' }} onClick={this.savemoban.bind(this)}>新增房间</p>
                                    {/* <p onClick={this.savemoban.bind(this)} className="btn">新增房间</p> */}

                                   
                                    {/* <p className="add" style={{ 'cursor': 'pointer' }} onClick={()=>{
                                    this.setState({showbtn:!0})
                                }}>隐藏按钮</p> */}
                                    {/* <p className="add" style={{ 'cursor': 'pointer' }} onClick={this.save.bind(this)}>保存</p> */}
                                    <p className="add" style={{ 'cursor': 'pointer' }} onClick={() => { window.location.href = './dz_main.html' }}>返回</p>

                                </div>
                                {/* <div style={{display:showbtn?'none':''}}>
                            <p className="add" style={{ 'cursor': 'pointer' }} onClick={()=>{
                                    this.setState({showbtn:!0})
                                }}>显示</p>
                            </div> */}
                            </div>

                            {/* <div>
                            备注内容
                            <textarea onChange={(e)=>{
                                let{value} =e.target
                            //   console.log(,'eeeeee');
                              //  this.setState({})
                            }}  name="" id="" cols="30" rows="10"></textarea>
                        </div> */}
 



                        </div>

                    </div >
                </div>

            </div >


        )
    }
}





ReactDOM.render(
    <div>
        {/* <LeftMenu code='0' /> */}
        <FirstPage />
    </div>
    //<Barrage/>
    , $('.container')[0]
)